package client;

import java.util.ArrayList;
import java.util.Collections;

import javax.jmdns.ServiceEvent;

public abstract class Client {
	ServiceType t;
	ArrayList<Service> serverList;
	public Client(Service s){
		serverList = new ArrayList<Service>();
		serverList.add(s);
	}
	public ServiceType getType(){
		return t;
	}
	public void setType(ServiceType type){
		t = type;
	}
	public void addService(Service newService) {
		serverList.add(newService);
	}
	public void removeService(ServiceEvent oldService){
		Service rem = null;
		for (Service thisService : serverList) {
			System.out.println(thisService.getServiceName()+" == "+oldService.getName());
			if(thisService.getServiceName().equals(oldService.getName())){
				rem = thisService;
				break;
			}
		}
		serverList.remove(rem);
	}
	
	public Service getServer(){
		if(serverList.isEmpty())
			return null;
		if(serverList.size() ==1)
			return serverList.get(0);
		Collections.shuffle(serverList);
		return serverList.get(0);
	}
}
